<?
// handle errors
handle_error($errors);
?>
<!DOCTYPE HTML><html>
<head>
<? echo $h->meta($title, $kwd, $dpn); ?>
<? require_once("lib.php"); ?>
<script src="<?=$ecom?>/js/jquery.validate.js" type="text/javascript"></script>
<script src="<?=$ecom?>/js/jquery.metadata.js" type="text/javascript"></script>
</head>

<body>
<? include_once("header.php"); ?>
<div id="wrap">
	<div id="main">
		<ul class="flow_step">
			<li>...</li>
			<li class="step1"><?=$order_status?></li>
			<li>...</li>
		<div class="clear"></div>
		</ul><!--flow_step end -->
		<? 
		// 若有实体商品, 加载地址
		if(! $are_virtual){
		?>
		<div id="addr_box">
			<div id="order_title"><?=WEB_ADDRESS_BOOK?></div>
			<ul class="order_address_list">
				<?
					$tem_province=$province->get_name($info['province'],$lang);
					$tem_addr=$tem_province;
					if(! empty($info['city'])) { $tem_city=$city->get_name($info['city'],$lang); $tem_addr.=$tem_city.'/'; }
					if(! empty($info['county'])) { $tem_county=$county->get_name($info['county'],$lang); $tem_addr.=$tem_county.'/'; }
					$tem_addr.=' '.$info['address'].', &nbsp; '.$info['contact_name'].' '.$info['mobile'];
				?>
				<li class="  selected  delete4">
				<div class="order_address_info">
					<span class="c1 radio_wrap"><input checked  id="radio4" type="radio" name="address_id"></input></span>
					<label class="radio_desp" for="radio4">
					<span class="c3"> &nbsp; <?=$tem_addr?></span></label>
				</div>
				<div class="clear"></div>
				</li>
				</ul>
		</div><!--addr_box end-->
		<? } else { ?>
		<div id="addr_box">
			<div id="order_title"><?=WEB_ADDRESS_BOOK?></div>
			<ul class="order_address_list">
				<li class="  selected  delete4">
				<div class="order_address_info">
					<span class="c1 radio_wrap"><input checked  id="radio4" type="radio" name="address_id"></input></span>
					<label class="radio_desp" for="radio4">
					<span class="c3"> &nbsp; <?=$info['contact_name'].' '.$info['mobile']?></span></label>
				</div>
				<div class="clear"></div>
				</li>
				</ul>
		</div><!--addr_box end-->
		<? } ?>
		
		<?
		// 若订单已付款, 或是货到付款的订单
		if($order_status_id>1 || ($order_status_id==1 && $payment_method_id==6)){ ?>
		<div id="pay_box">
			<div id="order_title"><?=WEB_PAYMENT_METHOD?></div>
			<div class="order_payment_area">
				<ul class="payment_bank_list">
					<?
						$str=''; $k==0;
						foreach($arr_payment as $key=>$row){
							// 银行转账未付款需要上传单据, 只需要显示银行转账
							if ($order_status_id==1 && $payment_method_id==6){
								if($key!=6) continue;
							}
							$checked='';
							if($k==0)$checked=' checked ';
							$str.='<li>
						<div class="payment_area"><input checked id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
							<label class="vam" for="pay_'.$k.'">';

							if(empty($row['pic']))$str.=$row['name_'.$lang];
							else $str.='<img src="upload/'.$row['pic'].'" height="36" />';

							$str.='</label>
						</div>
					</li>';
							$k++;
						}
						echo $str;
					?>
				</ul><!--payment_bank_list end--><div class="clear"></div>
				<?
				// 在线付款方式, 成功付款后显示单据
				if($payment_method_id!=5 && $payment_method_id!=6 && $order_status_id>1 && $order_status_id<6){?>
				<table class="receipt" width="100%">
						<tr><td width="120" class="tright"><?=WEB_PAYMENT_REF_NO?>:</td><td><?=$info['payment_ref_no']?></td></tr>
						<tr><td class="tright"><?=WEB_PAYER?>:</td><td><?=$info['payer']?></td></tr>
						<tr class="hide"><td class="tright"><?=WEB_PAYER_ID?>:</td><td><?=$info['payer_id']?></td></tr>
						<tr><td class="tright"><?=WEB_UPDATE_TIME?>:</td><td><?=$info['paid_time']?></td></tr>
					</table>
				<? }
				// 银行转账方式, 单据处理
				if($payment_method_id==6){
					if($order_status_id<3){
					echo $h->form('old_order.php',1,'need_check');
					echo $h->hidden('action','update');
					echo $h->hidden('ref_no',$ref_no);
					$receipt_button=' '.WEB_SUBMIT.' ';
					$not_first_time=0;
				?>
					<table class="receipt">
						<tr><td width="160" class="tright"><span class="red">*</span> <?=WEB_BANK_REF_NO?>:</td><td>
							<? if($info['payment_ref_no'] != '') { echo $info['payment_ref_no']; $not_first_time=1; }  else { ?>
							<input name="payment_ref_no" class="g {validate:{required:true,messages:{required:'<?=WEB_REQUIRED?>'}}}" />
						<? } ?>
						</td></tr>
						<tr><td class="tright"><span class="red">*</span> <?=WEB_BANK_ACCOUNT?>:</td><td>
							<? if($info['payer_id'] != '') { echo $info['payer_id']; $not_first_time=1; }  else { ?>
							<input name="payer_id" class="g {validate:{required:true,messages:{required:'<?=WEB_REQUIRED?>'}}}" />
							<? } ?>
						</td></tr>
						<tr><td class="tright"><span class="red">*</span> <?=WEB_BANK_ACCOUNT_OWNER?>:</td><td>
							<? if($info['payer'] != '') { echo $info['payer']; $not_first_time=1; } else { ?>
							<input name="payer" class="g {validate:{required:true,messages:{required:'<?=WEB_REQUIRED?>'}}}" />
							<?  } ?>
						</td></tr>
						<tr><td class="tright"><?=WEB_BANK_RECEIPT?>:</td><td>
							<? if($info['receipt_doc'] != ''){ ?>
							<a href="upload/<?=$info['receipt_doc']?>" target="_blank"><img src="upload/<?=$info['receipt_doc']?>" height="120" /></a><br />
							<? } ?>
							<? echo $h->cfile('cpic', 'g');
							if($not_first_time==1) $receipt_button=' '.WEB_UPDATE.' ';
							?></td></tr>
						<tr><td>&nbsp;</td><td><a class="button_blue" onclick="$('.need_check').submit();"><?=$receipt_button?></a></td></tr>
					</table>
					<? echo $h->former(); ?>
				<script type="text/javascript">
				$(document).ready(function(){
					$(".need_check").validate({meta: "validate", onkeyup: false, 
						errorPlacement: function( label, element ) {
							element.parent().append("<br>").append(label);
						}
					});
				}	);
				</script>
				<? }
					if( $order_status_id>2 && $order_status_id<6) { ?>
					<table class="receipt" width="100%">
						<tr><td width="120" class="tright"><?=WEB_BANK_REF_NO?>:</td><td><?=$info['payment_ref_no']?></td></tr>
						<tr><td class="tright"><?=WEB_BANK_ACCOUNT?>:</td><td><?=$info['payer_id']?></td></tr>
						<tr><td class="tright"><?=WEB_BANK_ACCOUNT_OWNER?>:</td><td><?=$info['payer']?></td></tr>
						<tr><td class="tright"><?=WEB_UPDATE_TIME?>:</td><td><?=$info['paid_time']?></td></tr>
						<tr><td class="tright"><?=WEB_BANK_RECEIPT?>:</td><td>
							<? if($info['receipt_doc'] != ''){ ?>
							<a href="upload/<?=$info['receipt_doc']?>" target="_blank"><img src="upload/<?=$info['receipt_doc']?>" height="120" /></a>
							<? } else echo WEB_NO_SUCH_DATA; ?>
						</td></tr>
					</table>
				<? }
				}
				?>
			</div><!--order_payment_area end-->
		</div><!--pay_box end-->

		<? } else {
			if($payment_method_id!=5){
			echo $h->form('checkout.php',0,'order_form');
			$key=md5('ecomgear'.date('Ymd'));
			echo $h->hidden('key',$key);

			$k=0;
			$str=$str2=$str3='';
			foreach($arr_payment as $key=>$row){
                if( $row['id']==7){
                    $str3='
                    <li style="width: 100%" class="my_wallet_payment">
                        <div class="my_wallet">
                            <input id="pay_wallet" class="use_balance" type="checkbox" name="use_balance" value="7" />
                            <label class="vam" for="pay_wallet">'.$row['name_'.$lang].'</label>
                            <input oninput="OnInput(event)" onpropertychange="OnPropChanged(event)" type="text" name="wallet" value="0" style="width: 30px; margin-left: 10px" maxlength="10" class="wallet">CNY
                            <label class="vam" for="pay_wallet" style="margin-left: 10px">余额：<span class="usable_balance blue">'.$customer_info['usable_balance'].'</span></label>
                        </div><br><br>
                        <div style="margin-left: 20px">*如果选择"我的钱包"付款，则不能组合"货到付款"方式</div>
                    </li>
                    ';
                }else{
					$checked='';
					if($k==0)$checked=' checked ';
					if(!empty($row['pic'])) $str.='<li>
				<div class="payment_area"><input '.$checked.' id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
					<label class="vam" for="pay_'.$k.'"><img src="upload/'.$row['pic'].'" height="36" /></label>
				</div>
			</li>';
					else $str2.='<li>
				<div class="payment_area">
					<input id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
					<label class="vam" for="pay_'.$k.'">'.$row['name_'.$lang].'</label>
				</div>
			</li>';
					$k++;
                }
				}
			?>
		<div id="pay_box">
			<div id="order_title"><?=WEB_PAYMENT_METHOD?></div>
			<div class="order_payment_area">
                <?if($str3!=''){?>
                <ul class="payment_bank_list">
                    <?echo $str3;?>
                </ul>
                <div class="clear"></div>
                    <?}?>
			<? if($str!=''){ ?>
				<div class="explain"><b><?=WEB_ONLINE_PAYMENT?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str ?>
				</ul><!--payment_bank_list end-->
                <div class="clear"></div>
				<? } ?>
				<? if($str2!=''){ ?>
				<div class="explain"><b><?=WEB_OTHER_METHOD?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str2 ?>
				</ul><!--payment_bank_list end-->
                <div class="clear"></div>
                <? } ?>
			</div><!--order_payment_area end-->
		</div><!--pay_box end-->
		<? }}
			$tem_hide=' hide ';
			if(! empty($info['invoice_header'])) $tem_hide='';
		?>
		<div id="pay_box" class="<?=$tem_hide?>">
			<div id="order_title"><?=WEB_INVOICE_INFO?></div>
			<div class="order_invoice_area">
				<table border="0" cellpadding="0" cellspacing="0">
            		<tbody>
                	<tr class="invoicer <?=$tem_invoice_hide?>">
            		<td><label class="vam" for="titleType-com"><?=WEB_INVOICE_HEADER?>: </label>&nbsp;&nbsp;
					<div class="inline-block"><?=$info['invoice_header'] ?></div></td>
                    	</tr>
                	</tbody>
            	</table>
			</div><!--order_invoice_area end-->
		</div><!--pay_box end-->
		<?
		// 若有实体商品, 加载物流信息
		if(! $are_virtual){
		?>
		<div id="pay_box">
			<div id="order_title"><?=WEB_SHIPMENT_METHOD?></div>
			<ul class="delivery_list">
				<?
				$str='';
				$k=0;
				foreach($arr_shipment as $row){
					$checked='';
					if($k==0)$checked=' checked ';
					$str.='<li>
				<div class="payment_area shipment'.$k.'"><input onclick="cal_price('.$k.')" '.$checked.' id="shipment_'.$k.'" class="radio" type="radio" name="shipment_method" value="'.$row['id'].'" />
					<label class="vam" for="shipment_'.$k.'">'.$row['name_'.$lang].'<span class="vam gray">'.WEB_SHIPMENT_FEE.' &nbsp; '.$order_currency_sign.'<em class="a_shipment_cost">'.$info['shipment_cost'].'</em></label>
					</div>
				</li>';
					$k++;
				}
				echo $str;
			?>
			</ul>
			<div class="clear"></div>
			<? if($order_status_id>3 && $order_status_id<6){
				$tem_shipment_method=$arr_shipment[$info['shipment_method_id']]['name_'.$lang];
				$tem_shipment_company=$arr_express['name_'.$lang];
				$tem_shipment_code=$info['shipment_tracking_no'];
				$tem_shipment_url=$arr_express['tracking_url'];
				$tem_shipment_phone=$arr_express['phone'];
				$tem_shipment_time=$info['shipped_time'];
			?>
				<table class="receipt" width="100%">
					<tr><td width="120" class="tright"><?=WEB_SHIPMENT_METHOD?>:</td><td><?=$tem_shipment_method?></td></tr>
					<tr><td width="120" class="tright"><?=WEB_SHIPMENT_COMPANY?>:</td><td><?=$tem_shipment_company?></td></tr>
					<tr><td class="tright"><?=WEB_SHIPMENT_TIME?>:</td><td><?=$tem_shipment_time?></td></tr>
					<tr><td class="tright"><?=WEB_TRACK_NO?>:</td><td><?=$tem_shipment_code?></td></tr>
					<tr><td class="tright"><?=WEB_SHIPMENT_HOTLINE?>:</td><td><?=$tem_shipment_phone?></td></tr>
					<tr><td class="tright"><?=WEB_TRACK_URL?>:</td><td><a target="_blank" class="blue" href="<?=$tem_shipment_url?>"><?=$tem_shipment_url?></a></td></tr>
				</table><br />
			<? } ?>
		</div><!--pay_box end-->
		<? } ?>
		<!--item list 商品明细-->
		<div id="pay_box">
			<div id="order_title"><?=WEB_ITEM_LIST?></div>
			<table class="table_cart" cellpadding="0" cellspacing="0">
			<thead class="list_cart">
				<tr>
				<th class="textcenter" width="360"><?=WEB_ITEM?></th>
				<th><?=WEB_UNIT_PRICE?></th>
				<th><?=WEB_QTY?></th>
				<th><?=WEB_SUBTOTAL?></th>
				</tr>
			</thead>
			<tbody>
			<?	
			$str='';
			$order_price=0;
			foreach($arr_cart as $row){
				$tem_product=$product->get_row($row['pid']);
				$tem_pic=$tem_product['small_pic'];
				$tem_link='product-'.$row['pid'].'.html';
				$tem_name=$tem_product['name_'.$lang];
				$tem_price=$row['unit_price'];
				$tem_qty=$row['qty'];
				$tem_total=$tem_qty*$tem_price;
				$order_price+=$tem_total;

				// variation
				$str_var='';
				$tem_var=$product_variation->get_row($row['var']);
				if($tem_var['size']) $str_var.=$option_label[2].': '.$option_value[$tem_var['size']].' &nbsp; ';
				if($tem_var['color']) $str_var.=$option_label[1].': '.$option_value[$tem_var['color']].' &nbsp; ';
				if($tem_var['other1']) $str_var.=$option_label[3].': '.$option_value[$tem_var['other1']].' &nbsp; ';
				if($tem_var['other2']) $str_var.=$option_label[4].': '.$option_value[$tem_var['other2']].' &nbsp; ';
				
				$str.='<tr>
			<td><div class="goods"><span class="image"><a href="'.$tem_link.'" target="_blank"><img src="'.PRODUCT_PIC_HOST.$tem_pic.'"/></a></span><div class="name"><a href="'.$tem_link.'" target="_blank">'.$tem_name.'</a><br /><br /><span class="gray">'.$str_var.'</span></div><div class="clear"></div></div></td>
			<td><strong class="price red">'.$order_currency_sign.' '.$tem_price.'</strong></td>
			<td>'.$tem_qty.'</td>
			<td><strong class="price">'.$order_currency_sign.' '.$tem_total.'</strong></td>
			</tr>';
			}
			echo $str;
			?>
			</tbody>
			<?
				// 表单 - 金额部分
				$shipment_fee=$info['shipment_cost'];
				$total_price=$info['total_price'];
				echo $h->hidden('total_price',$total_price,'total_price');
				echo $h->hidden('currency_code',$order_currency_code,'currency_sign');
				echo $h->hidden('ref_no',$ref_no,'ref_no');
				echo $h->hidden('payment_method_id',$info['payment_method_id'],'payment_method_id');
                echo $h->hidden('wallet_amount',0,'wallet_amount');
			?>
			<tfoot>
				<tr>
				<th colspan="4">
					<div class="customer_remark">
						<div><?=WEB_ORDER_REMARK?>: &nbsp; <?=empty($info['customer_remark'])?'-':$info['customer_remark']; ?></div>
					</div>
					<div class="price_check_box inherit">
						<div class="price_list">
							<div class="total">
							<p><span class="t"><?=WEB_TOTAL_FOR_ITEMS?>：</span><span class="txt price"><? echo $order_currency_sign.' '.$order_price ?></span></p>
							<? $nada=''; if($are_virtual) $nada=' class="hide" '; ?>
							<p <?=$nada?>><span class="t"><?=WEB_SHIPMENT_FEE?>：</span><span class="txt price"><? echo $order_currency_sign.'<span class="span_shipment_cost">'.$shipment_fee.'</span>' ?></span></p>
							<? $nada=''; if($info['coupon_discount_amount']==0) $nada=' class="hide" '; ?>
							<p <?=$nada?>><span class="t"><?=WEB_COUPON_AMOUNT?>：</span><span class="txt price"><? echo $order_currency_sign.'<span class="span_shipment_cost">'.$info['coupon_discount_amount'].'</span>' ?></span></p>
							<? $nada=''; if($info['point_discount_amount']==0) $nada=' class="hide" '; ?>
							<p <?=$nada?>><span class="t"><?=WEB_POINT_AMOUNT?>：</span><span class="txt price"><? echo $order_currency_sign.'<span class="span_shipment_cost">'.$info['point_discount_amount'].'</span>' ?></span></p>
							<? $nada=''; if(! $info['with_tax']) $nada=' class="hide" '; ?>
							<p id="div_tax"  <?=$nada?>><span class="t"><?=WEB_TAX?>：</span><span class="txt price"><? echo $order_currency_sign.' <span class="span_tax">'.$info['tax'].'</span>' ?></span></p>
                            <? $nada=''; ?>
                            <p <?=$nada?>><span class="t">钱包支付：</span><span class="txt price"><? echo $order_currency_sign.'<span class="span_wallet_amount">'.$info['wallet_amount'].'</span>' ?></span></p>
							<p><span class="t all"><?=WEB_SHOULD_PAY?>：</span> <span class="txt finalprice"><? echo $order_currency_sign.' <span class="span_total_price">'.$total_price.'</span>'; ?></span></p>
							</div>
							<? 
								$hide='hide';
								if($can_pay_online) $hide='';
							?>
							<div class="cart_buttom <?=$hide?>">
								<a class="payment" onclick="order_submit()"><?=WEB_ORDER_GOON?></a>
							</div>
						</div>
					<div class="clear"></div>
					</div>
				</th>
				</tr>
			</tfoot>
		</table>
		</div><!--pay_box end-->
		<? echo $h->former(); ?>
	</div><!--main end-->
</div><!--wrap end-->
<? include("footer.php"); ?>
<script type="text/javascript">
    var total_price = <?=$total_price?>;
    var use_balance = <?=$customer_info['usable_balance']?>;
    var wallet_amount = <?=$info['wallet_amount']?>;
    $(function(){
        var w = 0;
        $('input:checkbox[name="use_balance"]').click(function(){
            if(!w){
                $('input:checkbox[name="use_balance"]').prop('checked', true);
                $('input:radio[name="payment_method"]').each(function(){
                    if($(this).val() == 5){
                        $(this).attr('disabled', true);
                        $(this).attr('checked', false);
                        $(this).parent().css('color','#cccccc');
                    }
                });
                w = 1;
            }else{
                $('input:checkbox[name="use_balance"]').prop('checked', false);
                $('input:radio[name="payment_method"]').each(function(){
                    if($(this).val() == 5){
                        $(this).attr('disabled', false);
                        $(this).parent().css('color','#000000');
                    }
                });
                $('.span_total_price').html(total_price);
                $('.span_wallet_amount').html(wallet_amount);
                $('.usable_balance').html(use_balance);
                $('input:text[name="wallet"]').val(0);
                $('input:hidden[name="total_price"]').val(total_price);
                $('input:hidden[name="wallet_amount"]').val(0);
                w = 0;
            }
        });
        $('input:radio[name="payment_method"]').click(function(){
            if($(this).val() == 5){
                $('.my_wallet_payment').addClass('hide');
            }else{
                $('.my_wallet_payment').removeClass('hide');
            }
        });

        $('input:text[name="wallet"]').click(function(){
            $('input:checkbox[name="use_balance"]').prop('checked', true);
//            $('input:checkbox[name="use_balance"]').each(function(){$(this).attr('checked', 'checked')});
            $('input:radio[name="payment_method"]').each(function(){
                if($(this).val() == 5){
                    $(this).attr('disabled', true);
                    $(this).attr('checked', false);
                    $(this).parent().css('color','#cccccc');
                }
            });
            w = 1;
        });

        $('input:text[name="wallet"]').focus(function(){
            $('input:checkbox[name="use_balance"]').prop('checked', true);
//            $('input:checkbox[name="use_balance"]').each(function(){$(this).attr('checked', 'checked')});
            $('input:radio[name="payment_method"]').each(function(){
                if($(this).val() == 5){
                    $(this).attr('disabled', true);
                    $(this).attr('checked', false);
                    $(this).parent().css('color','#cccccc');
                }
            });
            w = 1;
        });
    });

    /*$('input:text[name="wallet"]').change(function(){
        var num = $(this).val();
        if(num!=''){
            alert(num);
        }
    });*/

    function OnInput (event) {
//        alert ("The new content: " + event.target.value);
        var this_price = parseFloat(event.target.value);
        var pay_price = 0;
        var balance = 0;
        var wallet = 0;
        if(this_price < 0 || isNaN(this_price)) {
            this_price = 0;
//            $('input:text[name="wallet"]').val(this_price);
        }
        pay_price = (total_price - this_price).toFixed(2);
        balance = (use_balance - this_price).toFixed(2);
        wallet = (wallet_amount + this_price).toFixed(2);

        if(this_price > total_price && this_price <= use_balance){
            $('input:text[name="wallet"]').val(total_price);
            this_price = total_price.toFixed(2);
            pay_price = 0;
            balance = (use_balance - this_price).toFixed(2);
            wallet = (wallet_amount + this_price).toFixed(2);
        }else if(this_price > use_balance && this_price <= total_price){
            $('input:text[name="wallet"]').val(use_balance);
            this_price = use_balance.toFixed(2);
            pay_price = (total_price - this_price).toFixed(2);
            balance = 0;
            wallet = (wallet_amount + this_price).toFixed(2);
        }else if(this_price > use_balance && this_price > total_price){
            if(total_price >= use_balance){
                $('input:text[name="wallet"]').val(use_balance);
                this_price = use_balance.toFixed(2);
                pay_price = (total_price - this_price).toFixed(2);
                balance = 0;
                wallet = (wallet_amount + this_price).toFixed(2);
            }else{
                $('input:text[name="wallet"]').val(total_price);
                this_price = total_price.toFixed(2);
                pay_price = 0;
                balance = (use_balance - this_price).toFixed(2);
                wallet = (wallet_amount + this_price).toFixed(2);
            }
        }

        $('.span_total_price').html(pay_price);
        $('.span_wallet_amount').html(wallet);
        $('.usable_balance').html(balance);
        $('input:hidden[name="total_price"]').val(pay_price);
        $('input:hidden[name="wallet_amount"]').val(this_price);
        if(this_price == 0){
            $('input:text[name="wallet"]').val();
        }else{
            $('input:text[name="wallet"]').val(this_price);
        }
    }

    function OnPropChanged (event) {
        if (event.propertyName.toLowerCase () == "value") {
//            alert ("The new content: " + event.srcElement.value);
            var this_price = parseFloat(event.srcElement.value);
            var pay_price = 0;
            var balance = 0;
            var wallet = 0;
            if(this_price < 0 || isNaN(this_price)) {
                this_price = 0;
//                $('input:text[name="wallet"]').val(this_price);
            }
            pay_price = (total_price - this_price).toFixed(2);
            balance = (use_balance - this_price).toFixed(2);
            wallet = (wallet_amount + this_price).toFixed(2);

            if(this_price > total_price && this_price <= use_balance){
                $('input:text[name="wallet"]').val(total_price);
                this_price = total_price.toFixed(2);
                pay_price = 0;
                balance = (use_balance - this_price).toFixed(2);
                wallet = (wallet_amount + this_price).toFixed(2);
            }else if(this_price > use_balance && this_price <= total_price){
                $('input:text[name="wallet"]').val(use_balance);
                this_price = use_balance.toFixed(2);
                pay_price = (total_price - this_price).toFixed(2);
                balance = 0;
                wallet = (wallet_amount + this_price).toFixed(2);
            }else if(this_price > use_balance && this_price > total_price){
                if(total_price >= use_balance){
                    $('input:text[name="wallet"]').val(use_balance);
                    this_price = use_balance.toFixed(2);
                    pay_price = (total_price - this_price).toFixed(2);
                    balance = 0;
                    wallet = (wallet_amount + this_price).toFixed(2);
                }else{
                    $('input:text[name="wallet"]').val(total_price);
                    this_price = total_price.toFixed(2);
                    pay_price = 0;
                    balance = (use_balance - this_price).toFixed(2);
                    wallet = (wallet_amount + this_price).toFixed(2);
                }
            }

            $('.span_total_price').html(pay_price);
            $('.span_wallet_amount').html(wallet);
            $('.usable_balance').html(balance);
            $('input:hidden[name="total_price"]').val(pay_price);
            $('input:hidden[name="wallet_amount"]').val(this_price)
            if(this_price == 0){
                $('input:text[name="wallet"]').val();
            }else{
                $('input:text[name="wallet"]').val(this_price);
            }

        }
    }
    /*$(function(){
        var select_change = $('select[name="category_id"]');
        select_change.triggerHandler('change');
    });*/
</script>
</body>
</html>